import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false;
// 导入组件
import CustomNav from './components/custom-nav.vue';
import CustomSelect from './components/custom-select.vue';
import CustomModal from './components/custom-modal.vue';
import PdfView from './components/pdf-view.vue';

Vue.component('CustomNav', CustomNav);
Vue.component('CustomSelect', CustomSelect);
Vue.component('CustomModal', CustomModal);
Vue.component('PdfView', PdfView);
App.mpType = 'app';
const app = new Vue({
	...App
})
app.$mount()
// #endif
// 路由拦截
Vue.mixin({
	onShow() {
		const currentPages = getCurrentPages();
		const currentRoute = currentPages[currentPages.length - 1].route;
		const token = uni.getStorageSync('token'); // 从本地存储获取 token
		// 如果没有 token 且当前页面不是登录页，则跳转到登录页
		const routes = ['pages/login/index', 'pages/home/index', 'pages/user/text']
		if (!token && !routes.includes(currentRoute)) {
			uni.showModal({
				title: '登录确认',
				content: '请您先进行登录！',
				showCancel: false,
				success: function(res) {
					if (res.confirm) {
						uni.navigateTo({
							url: '/pages/login/index'
						});
					}
				}
			});
		}
	}
});

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif